﻿<ResourceDictionary
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	xmlns:local="clr-namespace:BreadcrumbLib"
	xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
	xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
	xmlns:Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero"
	mc:Ignorable="d">
	<ResourceDictionary.MergedDictionaries>
		<ResourceDictionary Source="pack://application:,,,/BreadcrumbLib;Component/Themes/Brushes.xaml"/>
	</ResourceDictionary.MergedDictionaries>

	<ItemsPanelTemplate x:Key="BreadcrumbPanel">
		<StackPanel Orientation="Horizontal"/>
	</ItemsPanelTemplate>

	<local:DebugConverter x:Key="debugConv"/>

	<Style x:Key="BreadcrumbContextMenu" TargetType="{x:Type ContextMenu}">
		<Setter Property="Background"  Value="{StaticResource ContextMenuBackgroundBrush}" />
		<Setter Property="FontFamily"
                Value="{DynamicResource {x:Static SystemFonts.MenuFontFamilyKey}}"/>
		<Setter Property="FontSize"
                Value="{DynamicResource {x:Static SystemFonts.MenuFontSizeKey}}"/>
		<Setter Property="FontStyle"
                Value="{DynamicResource {x:Static SystemFonts.MenuFontStyleKey}}"/>
		<Setter Property="FontWeight"
                Value="{DynamicResource {x:Static SystemFonts.MenuFontWeightKey}}"/>
		<Setter Property="Foreground"
                Value="{DynamicResource {x:Static SystemColors.MenuTextBrushKey}}"/>
    <Setter Property="VerticalContentAlignment"
                Value="Center"/>
		<Setter Property="BorderThickness"
                Value="1"/>
		<Setter Property="BorderBrush"
                Value="#FF959595"/>
		<Setter Property="Padding"
                Value="2"/>
		<Setter Property="Grid.IsSharedSizeScope"
                Value="true"/>
		<Setter Property="HasDropShadow"
                Value="{DynamicResource {x:Static SystemParameters.DropShadowKey}}"/>
		<Setter Property="Template">
			<Setter.Value>
				<ControlTemplate TargetType="{x:Type ContextMenu}">
					<Themes:SystemDropShadowChrome Name="Shdw"
                                                  Color="Transparent"
                                                  SnapsToDevicePixels="true">
						<Border Background="{TemplateBinding Background}"
                                BorderBrush="{TemplateBinding BorderBrush}"
                                BorderThickness="{TemplateBinding BorderThickness}">
							<Grid>
								<Rectangle Fill="#F1F1F1"
                                           HorizontalAlignment="Left"
                                           Width="28"
                                           Margin="2"
                                           RadiusX="2"
                                           RadiusY="2"/>
								<Rectangle HorizontalAlignment="Left"
                                           Width="1"
                                           Margin="25,2,10,2"
                                           Fill="#E2E3E3"/>
								<Rectangle HorizontalAlignment="Left"
                                           Width="1"
                                           Margin="26,2,10,2"
                                           Fill="White"/>


								<ScrollViewer CanContentScroll="true"
                                              Grid.ColumnSpan="2" Margin="1,0"
                                              Style="{DynamicResource {ComponentResourceKey TypeInTargetAssembly={x:Type FrameworkElement}, ResourceId=MenuScrollViewer}}">
									<ItemsPresenter Margin="{TemplateBinding Padding}"
                                                    KeyboardNavigation.DirectionalNavigation="Cycle"
                                                    SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
								</ScrollViewer>
							</Grid>
						</Border>
					</Themes:SystemDropShadowChrome>
					<ControlTemplate.Triggers>
						<Trigger Property="HasDropShadow"
                                 Value="true">
							<Setter TargetName="Shdw"
                                    Property="Margin"
                                    Value="0,0,5,5"/>
							<Setter TargetName="Shdw"
                                    Property="Color"
                                    Value="#71000000"/>
						</Trigger>
					</ControlTemplate.Triggers>
				</ControlTemplate>
			</Setter.Value>
		</Setter>
	</Style>
	
	<ControlTemplate x:Key="BaseBreadcrumbButton" TargetType="{x:Type Button}">
		<Border x:Name="border"
				Background="{TemplateBinding Background}"
				BorderBrush="{TemplateBinding BorderBrush}"
				BorderThickness="{TemplateBinding BorderThickness}"
				SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
			<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" Margin="{TemplateBinding Padding}"/>
		</Border>
	</ControlTemplate>

	<Geometry x:Key="NormalArrow">M0,0 L4,3.5 0,7 z</Geometry>
	<Geometry x:Key="ExpandedArrow">M0,3 L7,3 3.5,7 z</Geometry>

	<ControlTemplate x:Key="BreadcrumbArrowButton" TargetType="{x:Type ToggleButton}">
		<Border x:Name="border"
				Background="{TemplateBinding Background}"
				BorderBrush="{TemplateBinding BorderBrush}"
				BorderThickness="{TemplateBinding BorderThickness}"
				SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" MinWidth="12">
			<Path x:Name="path"
				  Fill="#FF000000"
				  Data="{StaticResource NormalArrow}" 
				  HorizontalAlignment="Center"
				  VerticalAlignment="Center"
				  Margin="{TemplateBinding Padding}" IsHitTestVisible="False"/>
		</Border>
		<ControlTemplate.Triggers>
			<Trigger Property="IsPressed" Value="True">
				<Setter Property="Data" TargetName="path" Value="{StaticResource ExpandedArrow}"/>
			</Trigger>
			<Trigger Property="IsChecked" Value="True">
				<Setter Property="Data" TargetName="path" Value="{StaticResource ExpandedArrow}"/>
			</Trigger>
		</ControlTemplate.Triggers>
	</ControlTemplate>

	<local:ImageToImageConverter x:Key="ImageToImageConverter"/>
	
	<Style TargetType="{x:Type local:BreadcrumbButton}">
		<Setter Property="FontFamily" Value="Verdana"/>
		<Setter Property="FontSize" Value="8.25pt"/>
		<Setter Property="Template">
			<Setter.Value>
				<ControlTemplate TargetType="{x:Type local:BreadcrumbButton}">
					<StackPanel Orientation="Horizontal" Background="#FFFFFFFF" x:Name="stackPanel" SnapsToDevicePixels="True">
						<StackPanel.Resources>
							<BooleanToVisibilityConverter x:Key="boolToVis"/>
							<local:DebugConverter x:Key="debugConv"/>
						</StackPanel.Resources>
						<ContentPresenter x:Name="image"
										  Content="{Binding Path=View.SelectedItem.Image, Mode=Default}"
										  Visibility="Collapsed" />
						<Path Stretch="Fill" Stroke="#FF3C80B0" Data="m0,0 v1" x:Name="path" Visibility="Hidden" StrokeThickness="1" Margin="0,-0.5,0,-0.5"/>
						<Button x:Name="button"
							Content="{Binding Path=Header}"
							Command="{x:Static local:BreadcrumbButton.GoToCommand}"
							CommandParameter="{Binding}"
							Template="{StaticResource BaseBreadcrumbButton}"
							Background="{x:Null}"
							BorderBrush="#FFFFFFFF"
							RenderTransformOrigin="0.5,0.5"
							BorderThickness="1,1,1,1"
							Focusable="False"
							Padding="5,0,5,0"/>
						<Path Stretch="Fill" Stroke="#FF3C80B0" Data="M0,0 V1" x:Name="path1" Visibility="Hidden" Margin="0,-0.5,0,-0.5"/>
						<ToggleButton x:Name="buttonExpand"
							IsChecked="{Binding Path=IsExpanded}"
							ClickMode="Press"
							Visibility="{Binding Path=HasItems, Converter={StaticResource boolToVis}}"
							Template="{StaticResource BreadcrumbArrowButton}"
							Content="{StaticResource NormalArrow}"
							Background="#FFFFFFFF"
							BorderBrush="#FFFFFFFF"
							BorderThickness="1,1,1,1"
							Focusable="False">
							<ToggleButton.ContextMenu>
								<ContextMenu x:Name="menu"
									ItemsSource="{Binding Path=Items}"
									IsOpen="{Binding Path=IsExpanded}">
									<ContextMenu.Resources>
										<Style TargetType="{x:Type MenuItem}">
											<Setter Property="Command" Value="{x:Static local:BreadcrumbButton.InvokeMenuCommand}"/>
											<Setter Property="CommandParameter" Value="{Binding}"/>
											<Setter Property="Icon" Value="{Binding Path=Image, Converter={StaticResource ImageToImageConverter}}"/>
											<Setter Property="Padding" Value="2,4,0,0" />
											<Setter Property="Height" Value="22" />
											<Style.Triggers>
												<Trigger Property="IsHighlighted" Value="True">
													<Setter Property="Foreground" Value="Black"/>
												</Trigger>
											</Style.Triggers>
										</Style>
									</ContextMenu.Resources>
									<ContextMenu.Style>
										<StaticResource ResourceKey="BreadcrumbContextMenu"/>
									</ContextMenu.Style>
									<ContextMenu.CommandBindings>
										<CommandBinding Command="{x:Static local:BreadcrumbButton.GoToCommand}"/>
									</ContextMenu.CommandBindings>
								</ContextMenu>
							</ToggleButton.ContextMenu>
						</ToggleButton>
						<Path Stretch="Fill" Stroke="#FF3C80B0" Data="M0,0 V1" x:Name="path2" Visibility="Hidden" Margin="0,-0.5,0,-0.5"/>
					</StackPanel>
					<ControlTemplate.Triggers>
						<DataTrigger Binding="{Binding IsFirst}" Value="True">
							<Setter Property="Visibility" TargetName="image" Value="Visible"/>
						</DataTrigger>
						<Trigger Property="IsMouseOver" Value="True">
							<Setter Property="Background" TargetName="button">
								<Setter.Value>
									<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
										<GradientStop Color="#FFFFFFFF" Offset="0"/>
										<GradientStop Color="#FFCECECE" Offset="1"/>
									</LinearGradientBrush>
								</Setter.Value>
							</Setter>
							<Setter Property="Background" TargetName="buttonExpand" Value="{StaticResource ButtonMouseOver}"/>
							<Setter Property="Visibility" TargetName="path" Value="Visible"/>
							<Setter Property="Visibility" TargetName="path1" Value="Visible"/>
						</Trigger>
							<Trigger Property="IsMouseOver" Value="True" SourceName="button">
							<Setter Property="Background" TargetName="button" Value="{StaticResource ButtonMouseOver}"/>
						</Trigger>
						<MultiTrigger>
							<MultiTrigger.Conditions>
								<Condition Property="IsMouseOver" Value="True" />
								<Condition Property="Visibility" Value="Visible" SourceName="buttonExpand" />
							</MultiTrigger.Conditions>
							<Setter Property="Visibility" TargetName="path2" Value="Visible"/>
						</MultiTrigger>
						<Trigger Property="IsChecked" Value="True" SourceName="buttonExpand">
							<Setter Property="Background" TargetName="buttonExpand" Value="{StaticResource ButtonMouseOver}"/>
							<Setter Property="Background" TargetName="button" Value="{StaticResource ButtonMouseOver}"/>
							<Setter Property="Visibility" TargetName="path" Value="Visible"/>
							<Setter Property="Visibility" TargetName="path1" Value="Visible"/>
							<Setter Property="Visibility" TargetName="path2" Value="Visible"/>
							<Setter Property="BorderBrush" TargetName="buttonExpand" Value="{StaticResource BorderPressedBrush}"/>
							<Setter Property="BorderThickness" TargetName="buttonExpand" Value="1,1,0,0"/>
							<Setter Property="BorderBrush" TargetName="button" Value="{StaticResource BorderPressedBrush}"/>
							<Setter Property="BorderThickness" TargetName="button" Value="1,1,0,0"/>
							<Setter Property="Margin" TargetName="buttonExpand" Value="0,0,0,0"/>
							<Setter Property="Padding" TargetName="buttonExpand" Value="0,-2,0,0"/>
							<Setter Property="Padding" TargetName="button" Value="6,0,5,0"/>
						</Trigger>
						<Trigger Property="IsPressed" Value="True" SourceName="button">
							<Setter Property="Background" TargetName="buttonExpand" Value="{StaticResource ButtonMouseOver}"/>
							<Setter Property="Background" TargetName="button" Value="{StaticResource ButtonMouseOver}"/>
							<Setter Property="Visibility" TargetName="path" Value="Visible"/>
							<Setter Property="Visibility" TargetName="path1" Value="Visible"/>
							<Setter Property="Visibility" TargetName="path2" Value="Visible"/>
							<Setter Property="BorderBrush" TargetName="buttonExpand" Value="{StaticResource BorderPressedBrush}"/>
							<Setter Property="BorderThickness" TargetName="buttonExpand" Value="1,1,0,0"/>
							<Setter Property="BorderThickness" TargetName="button" Value="1,1,0,0"/>
							<Setter Property="Margin" TargetName="buttonExpand" Value="0,0,0,0"/>
							<Setter Property="Padding" TargetName="buttonExpand" Value="-1,-2,0,0"/>
							<Setter Property="BorderBrush" TargetName="button" Value="{StaticResource BorderPressedBrush}"/>
							<Setter Property="Padding" TargetName="button" Value="6,0,5,0"/>
						</Trigger>
					</ControlTemplate.Triggers>
				</ControlTemplate>
			</Setter.Value>
		</Setter>
		<Setter Property="Focusable" Value="False"/>
	</Style>

	<Style TargetType="{x:Type local:BreadcrumbItem}">
		<Setter Property="Template">
			<Setter.Value>
				<ControlTemplate TargetType="{x:Type local:BreadcrumbItem}">
					<local:BreadcrumbButton DataContext="{Binding RelativeSource={RelativeSource TemplatedParent}}" x:Name="button"/>
				</ControlTemplate>
			</Setter.Value>
		</Setter>
		<Setter Property="Focusable" Value="False"/>
		<Setter Property="Image" Value="{Binding Path=Image, Mode=Default}"/>
	</Style>

	<ControlTemplate x:Key="AdditionalButton" TargetType="{x:Type Button}">
		<Border x:Name="border"
				Background="White"
				BorderBrush="White"
				BorderThickness="0,1,0,1"
				Focusable="False"
				SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
			<StackPanel Orientation="Horizontal">
				<Path x:Name="path"
					  DockPanel.Dock="Right"
					  Stretch="Fill"
					  Stroke="#FF7F7F7F"
					  Data="m0,0 v1"
					  StrokeThickness="1"
					  Margin="0,-1.5,0,-1.5"/>
				<ContentPresenter Focusable="False" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="{TemplateBinding Padding}"/>
			</StackPanel>
		</Border>
		<ControlTemplate.Triggers>
			<Trigger Property="IsPressed" Value="True">
				<Setter Property="Background" TargetName="border" Value="{StaticResource ButtonMouseOver}"/>
				<Setter Property="BorderBrush" TargetName="border" Value="{StaticResource BorderPressedBrush}"/>
				<Setter Property="BorderThickness" TargetName="border" Value="0,1,0,0"/>
				<Setter Property="Padding" Value="0,1,0,0"/>
			</Trigger>
			<Trigger Property="IsMouseOver" Value="True">
				<Setter Property="Background" TargetName="border" Value="{StaticResource ButtonMouseOver}"/>
			</Trigger>
		</ControlTemplate.Triggers>
	</ControlTemplate>


	<Style TargetType="{x:Type local:Breadcrumb}">
		<Setter Property="Template">
			<Setter.Value>
				<ControlTemplate TargetType="{x:Type local:Breadcrumb}">
					<Border x:Name="outerBorder" BorderBrush="#CAF3F1F4" BorderThickness="1" CornerRadius="3,3,3,3">
						<Border x:Name="innerBorder"
								BorderBrush="{StaticResource GradientBorderBrush}"
								BorderThickness="1"
								CornerRadius="2,2,2,2"
								Background="{x:Null}">
							<DockPanel>
								<ItemsControl DockPanel.Dock="Right"
											  ItemsSource="{Binding Buttons, RelativeSource={RelativeSource TemplatedParent}}"
											  BorderThickness="0,0,0,0"
											  Focusable="False">
									<ItemsControl.ItemsPanel>
										<ItemsPanelTemplate>
											<StackPanel Orientation="Horizontal"/>
										</ItemsPanelTemplate>
									</ItemsControl.ItemsPanel>
									<ItemsControl.Resources>
										<Style TargetType="{x:Type Button}">
											<Setter Property="Template" Value="{StaticResource AdditionalButton}"/>
										</Style>
									</ItemsControl.Resources>
								</ItemsControl>
								<local:BreadcrumbView x:Name="PART_View"
                                    ItemsPanel="{StaticResource BreadcrumbPanel}"
                                    Focusable="False"
                                    Background="#FFFFFFFF"
                                    BorderThickness="0,0,0,0" />
							</DockPanel>
						</Border>
					</Border>
				</ControlTemplate>
			</Setter.Value>
		</Setter>
		<Setter Property="Height" Value="24"/>
		<Setter Property="Padding" Value="1,1,1,1"/>
	</Style>
</ResourceDictionary>